package com.example.treasure_back.utils;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime",new Timestamp(new Date().getTime()), metaObject);
        this.setFieldValByName("today",new Date(),metaObject);
        this.setFieldValByName("getTime", new Date(), metaObject);
        this.setFieldValByName("exchangeTime", new Date(), metaObject);
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.add(Calendar.DATE,30);
        this.setFieldValByName("dueTime", cal.getTime(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("today",new Date(),metaObject);
        this.setFieldValByName("exchangeTime", new Date(), metaObject);
    }

}